package com.fs.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.mapper.ReserveMapper;
import com.fs.mapper.WareHouse;
import com.fs.pojo.WhWarehouse;
import com.fs.pojo.Wh_inventory;
import com.fs.service.ReserveService;
import com.fs.service.WareHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @author hyy
 * @version 1.0
 * @description: 仓库服务实现
 * @date 2024/10/11 15:13
 */
@Service
public class WareHouseServiceImpl implements WareHouseService {
    @Autowired
    private WareHouse wareHouse;

    @Resource
    private ReserveMapper reserveMapper;


    @Override
    public Integer addWareHouse(WhWarehouse whWarehouse) {
        return wareHouse.insert(whWarehouse);
    }

    @Override
    public Integer delWareHouse(Integer id) {
        return wareHouse.deleteById(id);
    }

    @Override
    public Integer updateWareHouse(WhWarehouse whWarehouse) {
        return wareHouse.updateById(whWarehouse);
    }

    @Override
    public Page<WhWarehouse> queryWareHouse(Integer pageNum, Integer pageSize, WhWarehouse whWarehouse) {
            Page<WhWarehouse> page = new Page<>(pageNum,pageSize);
            LambdaQueryWrapper<WhWarehouse> wrapper = new LambdaQueryWrapper<WhWarehouse>();
            if (Objects.nonNull(whWarehouse)){
                //仓库名称模糊查询
               wrapper.like(whWarehouse.getWarehouseName()!=null,WhWarehouse::getWarehouseName,whWarehouse.getWarehouseName())
                       //仓库地址模糊查询
                       .like(whWarehouse.getWarehouseLocation()!=null,WhWarehouse::getWarehouseLocation,whWarehouse.getWarehouseLocation())
                       //仓库联系人查询
                       .eq(whWarehouse.getWarehouseResponsible()!=null,WhWarehouse::getWarehouseResponsible,whWarehouse.getWarehouseResponsible());
            }
            return wareHouse.selectPage(page,wrapper);
    }


    @Override
    public WhWarehouse queryWareHouseById(Integer id) {
        return wareHouse.selectById(id);
    }

    @Override
    public List<WhWarehouse> queryAll() {
        return wareHouse.selectList(null);
    }

    @Override
    public List<Wh_inventory> queryByProductId(Integer id) {
        return reserveMapper.selectList(new LambdaQueryWrapper<Wh_inventory>().eq(Wh_inventory::getProductId,id));
    }

}
